<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script>
        let proxy = new Proxy({}, {
            // get方法，用来拦截对目标对象属性的访问请求
            get: function (target, propKey) {
                return 23;
            }
        });
        console.log(proxy.time);
        console.log(proxy.name);
        console.log(proxy.age);


        let proxy1 = new Proxy({}, {
            get: function (target, propKey) {
                return 35;
            }
        });
        let obj = Object.create(proxy1);
        console.log(obj.time);


        let person = {
            name: 'chen'
        }
        let proxyget = new Proxy(person, {
            get(target, p, receiver) {
                if (p in target) {
                    return target[p];
                } else {
                    throw new ReferenceError("Prop name \"" + p + "\" is not exist.")
                }
            }
        })
        console.log(proxyget.name); // chen
        console.log(proxyget.age); // 抛出异常
    </script>

</head>
<body>

</body>
</html>